from PyQt5.QtWidgets import QMainWindow, QTabWidget, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton
from ui.tabs.tab_entry import TabEntry
from ui.tabs.tab_query import TabQuery
from ui.tabs.tab_other import TabOther
# ⚠️ 注意：这里先不要 import ProjectManager

class MainWindow(QMainWindow):
    def __init__(self, project):
        super().__init__()
        self.project = project
        self.setWindowTitle(f"银行流水系统 - {project}")
        self.resize(1000, 600)

        # ===== 主布局（上方标题 + TabWidget） =====
        main_widget = QWidget()
        main_layout = QVBoxLayout()

        # 顶部工具栏
        top_bar = QHBoxLayout()
        self.lbl_project = QLabel(f"当前项目：{self.project}")
        self.btn_back = QPushButton("返回项目管理")
        self.btn_back.clicked.connect(self.back_to_manager)

        top_bar.addWidget(self.lbl_project)
        top_bar.addStretch(1)
        top_bar.addWidget(self.btn_back)

        # 标签页
        self.tabs = QTabWidget()
        self.tabs.addTab(TabEntry(self.project), "录入系统")
        self.tabs.addTab(TabQuery(self.project), "查询数据")
        self.tabs.addTab(TabOther(self.project), "其他功能")

        main_layout.addLayout(top_bar)
        main_layout.addWidget(self.tabs)
        main_widget.setLayout(main_layout)
        self.setCentralWidget(main_widget)

    def back_to_manager(self):
        """返回项目管理界面"""
        # ✅ 延迟导入，避免循环引用
        from ui.project_manager import ProjectManager  
        self.manager = ProjectManager()
        self.manager.show()
        self.close()
